package com.example.qrcodecamera;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MidadminActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_midadmin);
        setTitle("管理员页面"); // 设置标题

        Button btnWeight = findViewById(R.id.btn_weight_record);
        Button btnMaterial = findViewById(R.id.btn_material_info);
        Button btnBack = findViewById(R.id.btn_back);
        Button btnupload = findViewById(R.id.btn_data_upload);
        Button btnmaterialupload = findViewById(R.id.btn_materialdata_upload);
        Button btnmysqlmake = findViewById(R.id.btn_mysql_make);

        btnupload.setOnClickListener(v->{startActivity(new Intent(this, UploadCSVActivity.class)
        );});

        btnmaterialupload.setOnClickListener(v->{startActivity(new Intent(this, MaterialuploadActivity.class)
        );});

        btnmysqlmake.setOnClickListener(v->{startActivity(new Intent(this, DBConfigActivity.class)
        );});

        // 添加空值检查以防止空指针异常
        if (btnWeight != null) {
            btnWeight.setOnClickListener(v -> {
                startActivity(new Intent(this, WeightRecordDecodeActivity.class));
            });
        } else {
            Toast.makeText(this, "按钮未找到: btn_weight_record", Toast.LENGTH_SHORT).show();
        }

        if (btnMaterial != null) {
            btnMaterial.setOnClickListener(v -> {
                startActivity(new Intent(this, MaterialInfoDecodeActivity.class));
            });
        } else {
            Toast.makeText(this, "按钮未找到: btn_material_info", Toast.LENGTH_SHORT).show();
        }
        
        // 返回按钮点击事件
        if (btnBack != null) {
            btnBack.setOnClickListener(v -> {
                startActivity(new Intent(this, LoginActivity.class));
                finish(); // 结束当前Activity
            });
        } else {
            Toast.makeText(this, "按钮未找到: btn_back", Toast.LENGTH_SHORT).show();
        }
    }
}